<?php

namespace app\admin\controller;

use app\admin\controller\BaseController;
use think\Request;
use think\Validate;

class ConfigGroup extends BaseController
{
    // 设置模型名称
    protected $modelName = 'config_group';

    protected $uniqueFields = ['name'];

    protected $fieldLabels = [
        'name' => '分组名称',
    ];

    // 设置验证规则
    // 添加自定义string验证规则
    public function __construct()
    {
        parent::__construct();
        Validate::extend('string', function ($value) {
            return is_string($value);
        }, '必须是字符串类型');
    }

    // 设置验证规则
    protected $validateRules = [
        'id' => 'number',
        'name' => 'require|max:10',
    ];

    // 设置规则提示
    protected $validateRulesMsg = [
        'name.require' => '分组名称不能为空',
        'name.max' => '分组名称最多10个字符',
    ];

    /**
     * 配置分组列表
     * */
    public function getList()
    {
        $list = $this->model->order('sort asc')->select();
        apiReturn(1, '获取成功', $list);
    }
}
